package com.tudou.api.bean;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class PlaylistInfo {
	public String playlistCode, title, description, createDate, modifiedDate,
	ownerName, ownerNickname, tags, descriptionUrl, outerPlayerUrl, playlistUrl, playlistPicUrl;
	public String[] itemCodes;
	public int playTimes, channelId, subTimes, playlistId, ownerId,
	itemCount, currentItemId;
	
	public static PlaylistInfo[] parsePlaylist(String str){
		PlaylistInfo[] data = null;
		try {
			String multiResult = new JSONObject(str).getString("multiResult");
			JSONObject obj = new JSONObject(multiResult);
			JSONArray jarray = obj.getJSONArray("results");
			data = new PlaylistInfo[jarray.length()];
			for(int i = 0; i < data.length; i++){
				JSONObject jobj = jarray.getJSONObject(i);
				data[i] = new PlaylistInfo();
				data[i].description = jobj.getString("description");
				data[i].tags = jobj.getString("tags");
				data[i].title = jobj.getString("title");
				data[i].playTimes = jobj.getInt("playTimes");
				data[i].channelId = jobj.getInt("channelId");
				data[i].subTimes = jobj.getInt("subTimes");
				data[i].playlistId = jobj.getInt("playlistId");
				data[i].ownerId = jobj.getInt("ownerId");
				data[i].ownerNickname = jobj.getString("ownerNickname");
				data[i].ownerName = jobj.getString("ownerName");
				data[i].outerPlayerUrl = jobj.getString("outerPlayerUrl");
				data[i].playlistCode = jobj.getString("playlistCode");
				data[i].descriptionUrl = jobj.getString("descriptionUrl");
				data[i].createDate = jobj.getString("createDate");
				data[i].modifiedDate = jobj.getString("modifiedDate");
				data[i].playlistUrl = jobj.getString("playlistUrl");
				data[i].itemCount = jobj.getInt("itemCount");
				data[i].playlistPicUrl = jobj.getString("playlistPicUrl");
				data[i].currentItemId = jobj.getInt("currentItemId");
				JSONArray array = ((JSONArray) jobj.get("itemCodes"));
				data[i].itemCodes = new String[array.length()];
				for(int j = 0; j < array.length(); j++){
					data[i].itemCodes[j] = array.getString(j);
				}
				
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return data;
	}
}
